<?php
declare(strict_types=1);

namespace App\Models\Admin;

use App\Library\AppFunction;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class User extends \App\Models\User
{
    public function channel(): BelongsTo
    {
        return $this->belongsTo(UserChannel::class, "channel_uid", "uid");
    }

    public function author(): BelongsTo
    {
        return $this->belongsTo(Author::class, "uid", "user_uid");
    }

    public static function getCurrentWeekRegister(int $type = 0): array
    {
        $closureWhere = function ($query) use ($type) {
            $query->where("gender", "=", $type);
        };
        $weeks = AppFunction::getWeekDayData();
        $weeksUser = [];
        foreach ($weeks as $value) {
            $weeksUser[] = User::query()->where($closureWhere)
                ->whereBetween("created_at", [$value . " 00:00:00", $value . " 23:59:59"])
                ->count();
        }
        return $weeksUser;
    }
}
